package com.AAL.DAO;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.IStatusOfInvoiceDAO;
import com.AAL.Model.StatusOfInvoice;
import com.AAL.Utils.HibernateUtil;

public class StatusOfInvoiceDAO implements IStatusOfInvoiceDAO {

	@Override
	public StatusOfInvoice getStatusOfInvoice(int statusID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		StatusOfInvoice statusOfInvoice = (StatusOfInvoice) session.load(
				StatusOfInvoice.class, statusID);
		return statusOfInvoice;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<StatusOfInvoice> getAllStatusOfInvoices() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<StatusOfInvoice> lstStatusOfInvoices = null;
		try {
			lstStatusOfInvoices = (List<StatusOfInvoice>) session.createQuery(
					"from StatusOfInvoice").list();
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return lstStatusOfInvoices;
	}

}
